package iterator.impl;

import iterator.MyIterator;
import list.impl.MyLinkedList;

public class MyLinkedListIterator<T> implements MyIterator<T> {

    private MyLinkedList.Node<T> current;

    private final MyLinkedList<T> list;

    public MyLinkedListIterator(MyLinkedList<T> list) {
        this.list = list;
        this.current = list.getHead();
    }

    @Override
    public T next() {
        MyLinkedList.Node<T> pointer = this.current;
        if (pointer != null) {
            this.current = pointer.next;
            return pointer.getValue();
        }
        return null;
    }

    @Override
    public boolean hasNext() {
        return current != null;
    }
}
